function [seq] = make_sequence(file, frec)
% make_sequence  - turn the filename/frec into a number for sorting
% that looks like this:
% yrmodacc.frec
% where yr is the file year (2 digits), mo is the file month (2 digits), da is the file day (2 digits)
% cc is the file number in the day's experiment (a = 001, etc.), using 3 digits (just in case...)
% and frec is a 4 digit record number entry indicating the first record of the file
%


% 1 special cases:
% handle the "rig" designator.
% assume we use "_rn" for the rig.
%
[p, file] = fileparts(file); % see if we passed the name with an extension on it

j = findstr(file, '_r');
rig = [];
if(j > 0)
    rig = file(j+2);
    file = file(1:j-1); % simplilfy the file name...
end;
if(length(file) > 8 && file(4) == '_') % assume might have a user prepend on name
    j = findstr(file, '_'); % as in pbm_filename....
    file = file(j+1:end); % just clip the prepend from the filename
    % note  - we do NOTHING special to the sequence number for this file when doing this.
end;


if(length(file) == 8)
    da=file(1:2);
    mon=file(3:5);
    yr=file(6:7);
    ltr = double(upper(file(8)))-double('A')+1;
end;
if(length(file) == 7)
    da=file(1);
    mon=file(2:4);
    yr=file(5:6);
    ltr = double(upper(file(7)))-double('A')+1;
end;
if(length(file) > 8)
    da = file(1:2);
    mon = file(3:5);
    yr=file(6:7);
    ltr = double(upper(file(8)))-double('A')+1;
    frec = str2num(file(10:12));
end;

    

month=strvcat('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec');
monum=strmatch(lower(mon), month, 'exact');
seq = sprintf('%02s%02d%02s%03d.', yr, monum, da, ltr);
if(isempty(rig))
    seq=strcat(seq, sprintf('%05d', number_arg(frec)));
else
    seq=strcat(seq, sprintf('%1d%05d', number_arg(rig), number_arg(frec)));
end;
return
